#ifndef __ShipHandler__
#define __ShipHandler__

#include "ship.h"

class ShipHandler {
public:
    static ShipHandler* Instance() {
        if (s_pInstance == NULL) {
            s_pInstance = new ShipHandler();
            return s_pInstance;
        }
        return s_pInstance;
    }
    void addShips();
    void updateShips();
    void drawShips();
    void drawHits();
    void clearShips();
    const std::vector<Ship*> getShips() { return m_pShips; }
    bool valid(const Vector2D& pos) const;
    void add(int cx, int cy, Ship* ship);
    void add(int n);
    void addBorder(const Vector2D& pos);
    bool canAddShip(int cx, int cy, Ship* ship);
    void hit(const Vector2D& pos);
    Vector2D find(Ship* ship) const;
    bool isNearShip(const Vector2D& coord) const;
    int getFirstUnplacedShip(Ship::Owner owner) const;
    int gameFinished();
private:
    ShipHandler();
    ~ShipHandler();
    ShipHandler(const ShipHandler&);
    static ShipHandler* s_pInstance;
    std::vector<Ship*> m_playerShips;
    std::vector<Ship*> m_enemyShips;
    std::vector<Ship*> m_pShips;
    bool m_placingCompleteP, m_placingCompleteE;
    bool m_bReleasedR, m_bReleasedL; // mouse button
    int m_playerBoard[10][10], m_enemyBoard[10][10], m_playerHitInfo[10][10], m_enemyHitInfo[10][10];
    // board: 0 - water, size() - ship, 1 - hit, -1 - miss
    bool playerTurn;
};

typedef ShipHandler TheShipHandler;

#endif /* defined(__ShipHandler__) */
